home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / serial / zyxel-1.5 / zyxel-1 / usr / ZyXEL / voice < prev    next >
Text File  |  1994-10-23  |  12KB  |  448 lines

  1. #!/usr/X386/bin/wishx -f
  2. #
  3. #     #########       #       # ######### #
  4. #        #        #      #  #           #
  5. #          ##   #     #   #     #   #           #
  6. #         #       #     #    ###    #######   #
  7. #       ##       #     #   #     #   #           #
  8. #      #       #     #  #      #  #           #
  9. #     #########  ###### #       # ######### #########
  10. #             #
  11. #             #
  12. #            #####
  13. #
  14. #
  15. #    A Tcl/Tk interface to the ZyXEL control program written by 
  16. #    Rob Janssen, PE1CHL
  17. #
  18. #    This wish script is nothing more than a graphical interface
  19. #    to replace the cumbersome zvbm script. 
  20. #
  21. #    It also talks to the ZyXEL programm through the fifo
  22. #    (usaully /usr/ZyXEL/fifo.ttyS<x>). 
  23. #    Replies are read through another fifo.
  24. #
  25. #    Features:
  26. #    - playback recorded messages
  27. #    - archive messages
  28. #    - listen to or record a phone call
  29. #    - modem status information
  30. #    - fax viewing through external convertor + viewer
  31. #
  32. #
  33. #
  34. #    Copyright 1994 by Harm Arts (harm@es.ele.tue.nl)
  35. #
  36. #    Permission is hereby granted to copy, reproduce, redistribute,
  37. #    or otherwise use this software as long as: there is no monetary
  38. #    profit gained specifically from the use or reproduction or this
  39. #    software, it is not sold, rented, traded or otherwise marketed,
  40. #    and this copyright notice is included prominently in any copy
  41. #    made.
  42. #
  43. #    The author make no claims as to the fitness or correctness of
  44. #    this software for any use whatsoever, and it is provided as is.
  45. #    Any use of this software is at the user's own risk.
  46. #
  47. #
  48. #
  49. #    $Id: voice,v 2.4 1994/10/22 14:59:21 root Exp $
  50.  
  51. #############################################################################
  52. # configure as you like
  53. #############################################################################
  54.  
  55. # debuging info on stdout [0|1]
  56. set debug    0
  57.  
  58. # how to search for the fifo to talk to ZyXEL ($fdir.<tty>)
  59. set fdir    /usr/ZyXEL/fifo
  60.  
  61. # fifo to read what ZyXEL program answers
  62. set infile    /tmp/ZyXEL.fifo
  63.  
  64. # directories in which you store your play files and how to name them
  65. set playdirs  { "/usr/ZyXEL/play    Play"
  66.         "/usr/ZyXEL/archive    Archive"
  67.         "/usr/ZyXEL/record    Recorded"
  68.         "/usr/ZyXEL/fax        Fax" }
  69.  
  70. # index in playdirs to start up with
  71. set defaultdir    2
  72.  
  73. # list of indices in playdirs which may be archived
  74. set toarchive { 2 }
  75.  
  76. # index in playdirs to use as archive
  77. set archivedir    1
  78.  
  79. # index in playdirs where the ZyXEL programm puts recordings in
  80. set recdir    2
  81.  
  82. # default for speaker: internal or line
  83. set speaker    internal
  84.  
  85. # default volume for speaker [0-7]
  86. set defvol    6
  87.  
  88. # how to convert a CLASS 2 fax file into a visible file
  89. set fax2vis    "/home/harm/linux/apps/netpbm/pbm/g3topbm -rev -stretch"
  90.  
  91. # what extensio does the visible file have
  92. set visext    pbm
  93.  
  94. # how to view a visible fax file
  95. set visview    "xv -maxpect -geometry +0+0"
  96.  
  97. #############################################################################
  98. # procs
  99. #############################################################################
  100.  
  101. foreach i [winfo child .] {
  102.     catch {destroy $i}
  103. }
  104.  
  105. proc tkerror err {
  106.     global errorInfo
  107.     puts stderr "$errorInfo"
  108. }
  109.  
  110. proc Puts {s} {
  111.     global debug
  112.     if {$debug} { puts stdout $s }
  113. }
  114.  
  115. proc mkDialog {w msgArgs args} {
  116.     catch {destroy $w}
  117.     toplevel $w -class Dialog
  118.     set oldFocus [focus]
  119.     
  120.     frame $w.top -relief raised -border 1
  121.     frame $w.bot -relief raised -border 1
  122.     pack $w.top $w.bot -side top -fill both -expand yes
  123.     
  124.     eval message $w.top.msg -justify center \
  125.         -font -bitstream-*-medium-*-*-*-*-150-*-*-m-*-*-* $msgArgs
  126.     pack $w.top.msg -side top -expand yes -padx 2 -pady 2
  127.     
  128.     if {[llength $args] > 0} {
  129.     set arg [lindex $args 0]
  130.     frame $w.bot.0 -relief sunken -border 1
  131.     pack $w.bot.0 -side left -expand yes -padx 10 -pady 10
  132.     button $w.bot.0.button -text [lindex $arg 0] \
  133.         -command "[lindex $arg 1]; destroy $w; focus $oldFocus"
  134.     pack $w.bot.0.button -expand yes -padx 6 -pady 6
  135.     bind $w <1> "$w.bot.0.button config -relief sunken"
  136.     bind $w <ButtonRelease-1> \
  137.         "[lindex $arg 1]; $w.bot.0.button deactivate; destroy $w; focus $oldFocus"
  138.     bind $w <Return> "[lindex $arg 1]; destroy $w; focus $oldFocus"
  139.     focus $w
  140.     
  141.     set i 1
  142.     foreach arg [lrange $args 1 end] {
  143.         button $w.bot.$i -text [lindex $arg 0] \
  144.             -command "[lindex $arg 1]; focus $oldFocus"
  145.         pack $w.bot.$i -side left -expand yes -padx 10
  146.         set i [expr $i+1]
  147.     }
  148.     }
  149.     wm geometry $w +300+150
  150. }
  151.  
  152. proc MkList {dir} {
  153.     global visext
  154.     while {[.sb.list size] > 0} {
  155.     .sb.list delete 0
  156.     }
  157.     foreach sdir $dir {
  158.     foreach i [exec ls $sdir] {
  159.         # hide intermediate files
  160.         if { [string last .$visext $i] == -1 } {
  161.         .sb.list insert end $i 
  162.         }
  163.     }
  164.     }
  165. }
  166.  
  167. proc Pout {string} {
  168.     global pout
  169.     Puts "pout : $string"
  170.     puts $pout $string;    flush $pout
  171. }
  172.  
  173. proc MkBusy {val} {
  174.     global busy
  175.     set busy $val
  176.     if {$busy >  0} {set state normal} else {set state disabled}
  177.     .buttons.stop        config -state $state
  178.     if {$busy == 0} {set state normal} else {set state disabled}
  179.     .buttons.play        config -state $state
  180.     .buttons.record        config -state $state
  181.     .buttons.listen        config -state $state
  182.     .buttons.status        config -state $state
  183.     .speaker.vol.sc        config -state $state
  184.     .speaker.out.internal    config -state $state
  185.     .speaker.out.line        config -state $state
  186. }
  187.  
  188. proc CheckOk {} {
  189.     global busy
  190.     global Zpid
  191.     .buttons.stop    config -command {
  192.     .buttons.stop    config -state disabled
  193.     set pslist    [exec ps a]
  194.     Puts "exe: kill -2 $Zpid"
  195.     exec kill -2 $Zpid 
  196.     }
  197.     MkBusy [expr $busy+1]
  198.     signal trap SIGALRM {
  199.     global pin
  200.     set flist [select $pin {} {} 0]
  201.     if {[lindex $flist 0] == $pin} {
  202.         gets $pin answer
  203.         if {$answer != "" && $answer != "\r"} {        
  204.         Puts "tim  : $answer" 
  205.         }
  206.         if {[string first OK    $answer] == 0 ||
  207.         [string first ERROR $answer] == 0 } {
  208.         MkBusy [expr $busy-1] 
  209.         }
  210.     }
  211.     if {$busy >  0} { alarm 0.1 } 
  212.     }
  213.     alarm 0.1
  214. }
  215.  
  216. proc Play {file} {
  217.     set ext_index [string last . $file]
  218.     set ext [string range $file [expr $ext_index + 1] end]
  219.     if {"$ext" == "fax"} {
  220.     global visext
  221.     global visview
  222.     set base [string range $file 0 $ext_index]
  223.     if {![file exists $base$visext] } {
  224.         mkDialog .wait "-text {Converting fax to $visext.
  225.         This might take a while ...} \
  226.             -justify left"
  227.         update
  228.         global fax2vis
  229.         eval [concat exec \
  230.             $fax2vis $file > $base$visext 2>@ stderr]
  231.         destroy .wait
  232.     }
  233.     Puts "starting $visview $base$visext"
  234.     eval [concat exec $visview $base$visext &]
  235.     } else {
  236.     CheckOk
  237.     Pout "P $file"
  238.     }
  239. }
  240.  
  241. proc WaitOk {string} {
  242.     global pin
  243.     set answer ""
  244.     while {[string first $string $answer] != 0 &&
  245.     [string first ERROR   $answer] != 0} {
  246.     gets $pin answer
  247.     if {$answer != "" && $answer != "\r"} {        
  248.         Puts "pin  : $answer" 
  249.     } 
  250.     }
  251. }    
  252.  
  253. proc Volume {l} { Pout ATL$l ; WaitOk OK }
  254.  
  255. #############################################################################
  256. # start packing
  257. #############################################################################
  258.  
  259. set id    {$Id: voice,v 2.4 1994/10/22 14:59:21 root Exp $}
  260. set version [lindex $id 2]
  261. label .label -text "ZyXEL user interface, Version $version. (C) Harm Arts" \
  262.     -relief raised -borderwidth 2
  263. pack  .label -side top -fill both
  264.  
  265. frame .speaker -relief raised -borderwidth 2
  266. frame .speaker.out
  267. frame .speaker.vol
  268.  
  269. label        .speaker.out.label \
  270.     -text "Speaker output:"
  271. radiobutton     .speaker.out.internal \
  272.     -text "Internal" -relief flat \
  273.     -value "internal" -variable speaker \
  274.     -activebackground Bisque1 \
  275.     -command { Pout "S"; WaitOk SPEAKER}
  276. radiobutton    .speaker.out.line \
  277.     -text "Line" -relief flat \
  278.     -value "line" -variable speaker \
  279.     -activebackground Bisque1 \
  280.     -command { Pout "L"; WaitOk LINE}
  281. scale        .speaker.vol.sc \
  282.     -orient horizontal -length 10 -from 0 -to 7 \
  283.     -showvalue no  -tickinterval 1 -bg Bisque1 \
  284.     -command { Volume } -length 100 -sliderlength 10
  285. label         .speaker.vol.label \
  286.     -text "Speaker volume:"
  287.  
  288. pack .speaker.out.label .speaker.out.internal .speaker.out.line \
  289.     -side left -pady 2
  290. pack .speaker.vol.label .speaker.vol.sc -side left -fill both -padx 5
  291. place .speaker.vol.label -x 0
  292. pack .speaker.out .speaker.vol -side top
  293. pack .speaker -fill x
  294.  
  295. .speaker.vol.sc        set $defvol
  296. .speaker.out.internal    [expr "{$speaker}=={internal} ? {select} : {deselect}"]
  297. .speaker.out.line    [expr "{$speaker}!={internal} ? {select} : {deselect}"]
  298.  
  299.  
  300. frame .sb -relief raised -borderwidth 2
  301. frame .sb.rb
  302.  
  303. set i 1
  304. foreach arg $playdirs {
  305.     radiobutton .sb.rb.$i \
  306.         -variable dir -text "[lindex $arg 1]" -relief flat \
  307.         -value [lindex $arg 0] -activebackground Bisque1 \
  308.         -command { MkList $dir }
  309.     pack .sb.rb.$i -side left
  310.     set i [expr $i+1]
  311. }
  312.  
  313. scrollbar   .sb.scroll \
  314.     -command ".sb.list yview"
  315.  
  316. # pack .sb.rb.play .sb.rb.arc .sb.rb.rec -side left -anchor w
  317. pack .sb.rb -side top -anchor w
  318. pack .sb.scroll -side left -fill y
  319. listbox .sb.list -yscroll ".sb.scroll set" -geometry 20x20 \
  320.     -setgrid yes
  321. pack .sb.list -side right -fill both -expand yes
  322.  
  323. bind .sb.list <Double-Button-1> {
  324.     .buttons.play invoke
  325. }
  326.  
  327. frame .buttons -relief raised -border 1
  328. pack .sb .buttons -side left -fill both -expand yes
  329.  
  330. button .buttons.stop    -text "Stop" 
  331. button .buttons.play    -text "Play" 
  332. button .buttons.arch    -text "Archive" 
  333. button .buttons.listen    -text "Listen"
  334. button .buttons.record    -text "Record"
  335. button .buttons.status  -text "Status"
  336. button .buttons.delete  -text "Delete" 
  337. button .buttons.exit    -text "Exit"
  338.  
  339. pack    .buttons.stop   .buttons.play   .buttons.arch   .buttons.listen \
  340.     .buttons.record .buttons.status .buttons.delete .buttons.exit   \
  341.     -side top -fill both
  342.  
  343. .buttons.stop    config -state disabled
  344. .buttons.play    config -command {
  345.     if {[selection own] != ""} {
  346.     foreach i [selection get] { 
  347.         Play $dir/$i
  348.     }
  349.     }
  350. }
  351. .buttons.arch    config -command {
  352.     if { [selection own] != "" &&
  353.     [lsearch $toarchive [lsearch -glob $playdirs $dir*]] != -1 } {
  354.     while { [llength [.sb.list curselection]] > 0 } {
  355.         set index [lindex [.sb.list curselection] 0]
  356.         exec mv $dir/[.sb.list get $index] $archive
  357.         .sb.list delete $index
  358.     }
  359.     }
  360. }
  361. .buttons.listen    config -command {
  362.     Pout "ATM2H1"
  363.     WaitOk OK
  364.     .buttons.stop    config -command {
  365.     MkBusy 0; Pout "ATH0"; WaitOk OK
  366.     }
  367.     MkBusy 1
  368. }
  369. .buttons.record    config -command {
  370.     set dir [lindex [lindex $playdirs $recdir] 0]
  371.     Pout "R2"
  372.     CheckOk
  373.     MkList $dir
  374. }
  375. .buttons.status config -command {
  376.     Pout "ATI2"; global pin; set answer ""; set text ""
  377.     while { [string first OK    $answer] != 0 &&
  378.     [string first ERROR $answer] != 0} {
  379.     if {$answer != ""} {
  380.         set text $text\n[string trim $answer " \r"]
  381.     }
  382.     gets $pin answer
  383.     }
  384.     mkDialog .status "-text {$text} -justify left" "OK {}"
  385. }
  386. .buttons.delete config -command {
  387.     if {[selection own] != ""} {
  388.     while { [llength [.sb.list curselection]] > 0 } {
  389.         set index [lindex [.sb.list curselection] 0]
  390.         set file  [.sb.list get $index]
  391.         set ext   [string last .fax $file]
  392.         exec rm -f $dir/$file
  393.         if { $ext > -1 } {
  394.         set base [string range $file 0 $ext]
  395.         Puts "also removing $dir/$base$visext"
  396.         exec rm -f $dir/$base$visext
  397.         }
  398.         .sb.list delete $index
  399.     }
  400.     }
  401. }
  402. .buttons.exit    config -command {
  403.     destroy .
  404. }
  405.  
  406. #############################################################################
  407. # initialize
  408. #############################################################################
  409.  
  410. wm geometry . 30x9+50+100
  411.  
  412. set busy    0
  413.  
  414. set dir        [lindex [lindex $playdirs $defaultdir] 0]
  415. set archive    [lindex [lindex $playdirs $archivedir] 0]
  416.  
  417. MkList $dir
  418.  
  419. switch $argc {
  420.     0 { set fifo [exec sh -c "ls $fdir.*" | head -1] }
  421.     1 { set fifo $fdir.$argv }
  422.     default { puts stdout "Usage: $argv0 [ttySx]"; exit } 
  423. }
  424.  
  425. if {[file exists $infile]} {
  426.     if {[file type $infile] != "fifo"} {
  427.     puts stdout "Error: $infile allready exists and is not a fifo"
  428.     }
  429. } else {
  430.     exec mkfifo $infile
  431. }
  432.  
  433. set pout [open $fifo w]
  434. Puts "pout $fifo open"
  435. Pout "> $infile"
  436. set pin  [open $infile]
  437. Puts "pin  open"
  438. Pout "#"
  439. WaitOk ZyXEL
  440. Pout "!"
  441. gets $pin Zpid
  442. Puts "Zpid = $Zpid"
  443.  
  444. #############################################################################
  445. # now push and see what all buttons do
  446. #############################################################################
  447.  
  448.